package _021_11_17

type ListNode struct {
	Val  int
	Next *ListNode
}

var n_1_node *ListNode

func removeNthFromEnd(head *ListNode, n int) *ListNode {
	_n := back(n, head)
	if _n == n {
		head = head.Next
	}
	return head
}

func back(n int, head *ListNode) int {
	if head == nil {
		return 1
	}
	_n := back(n, head.Next)
	if _n == n {
		n_1_node = head
	}
	if _n == n+1 {
		head.Next = n_1_node.Next
	}
	return _n + 1
}
